home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / self / contrib.lha / contrib / 491 / aa / boundedNum.self < prev    next >
Encoding:
Text File  |  1993-05-30  |  1.4 KB  |  51 lines

  1. " A bounded number is a number that can get bigger and smaller, "
  2. " but only within some bounds (that may be infinite). If you add "
  3. " to it, for instance, and it gets too big, it won't grow any "
  4. " larger than the upper bound "
  5. "
  6. * boundedNum.self,v 1.3 1993/05/30 21:41:14 richards Exp
  7. *
  8. * boundedNum.self,v
  9. * Revision 1.3  1993/05/30  21:41:14  richards
  10. * CVS checkin.
  11. *
  12. * Revision 1.2  1993/05/14  22:42:25  richards
  13. * Bounded numbers now work properly in 2.0.1 and even print nicely.
  14. * +/- and * are supported operations that return a *new* bnum.
  15. *
  16. * Revision 1.1  1992/10/05  06:37:47  richards
  17. * Initial revision
  18. *
  19. *
  20. *
  21. "
  22.  
  23. aa traits _AddSlotsIfAbsent: ( | bnum = (). |)
  24.  
  25. aa traits bnum _Define: ( |
  26.     parent* = traits clonable.
  27.     printString = (
  28.     'Bnum<', (lower printString), '|', (upper printString), '>: ', (value printString)
  29.     ).
  30.     + aNumericThing = ( copy value: (aNumericThing + value) ).
  31.     - aNumericThing = ( copy value: (aNumericThing - value) ).
  32.     * aNumericThing = ( copy value: (aNumericThing * value) ).
  33.     value = ( val ).
  34.     value: x = ( | newval. |
  35.     newval: x max: lower.
  36.     newval: newval min: upper.
  37.     val: newval ).
  38. |)
  39.  
  40. aa prototypes _AddSlotsIfAbsent: ( | bnum = (). |)
  41.  
  42. aa prototypes bnum _Define: ( |
  43.           parent* = aa traits bnum.
  44.       thisObjectPrints = true.
  45.           upper <- infinity.
  46.           lower <- 0-infinity.  
  47.           val <- 0.
  48. |)
  49.  
  50.